package com.huazai.rabbitmq.config.exchange;

/**
 * @author huazai
 * @date 2024/11/11
 */
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitFanoutConfig {

    public static final String FANOUT_QUEUE_ONE = "fanoutQueue-One";
    public static final String FANOUT_QUEUE_TWO = "fanoutQueue-Two";
    public static final String FANOUT_EX = "Fanout-Ex";

    @Bean
    public Queue fanoutQueue(){
        //参数介绍
        //1.队列名 2.是否持久化 3.是否独占 4.自动删除 5.其他参数
        return new Queue(FANOUT_QUEUE_ONE,false,false,false,null);
    }

    @Bean
    public Queue fanoutQueue2(){
        //参数介绍
        //1.队列名 2.是否持久化 3.是否独占 4.自动删除 5.其他参数
        return new Queue(FANOUT_QUEUE_TWO,false,false,false,null);
    }

    @Bean
    public FanoutExchange fanoutExchange(){
        //参数介绍
        //1.交换器名 2.是否持久化 3.自动删除 4.其他参数
        return new FanoutExchange(FANOUT_EX,false,false,null);
    }

    @Bean
    public Binding bingExchange(){
        return BindingBuilder.bind(fanoutQueue())   //绑定队列
                .to(fanoutExchange());       //队列绑定到哪个交换器
    }

    @Bean
    public Binding bingExchange2(){
        return BindingBuilder.bind(fanoutQueue2())   //绑定队列
                .to(fanoutExchange());       //队列绑定到哪个交换器
    }

}

